package com.huike.controller.adminController;


import com.huike.entity.Roles;
import com.huike.service.IRolesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lwen
 * @since 2019-12-28
 */
@Controller
@RequestMapping("/admin/roles")
public class RolesController {

    @Autowired
    IRolesService rolesService;

    /**
     * 为用户授权
     * @param menu_ids
     * @param user_id
     */
    @RequestMapping("/insertMenus")
    @ResponseBody
    public boolean insertMenus(@RequestParam(required = false,value = "menu_ids[]")List<String> menu_ids, String user_id){
        List<Roles> roles = rolesService.getRoles(menu_ids, user_id);
        return rolesService.insertRole(roles);
    }

    /**
     * 取消用户权限
     * @param menu_ids
     * @param user_id
     */
    @RequestMapping("/deleteMenus")
    @ResponseBody
    public boolean deleteMenus(@RequestParam(required = false,value = "menu_ids[]")List<String> menu_ids,String user_id){
        List<Roles> roles = rolesService.getRoles(menu_ids, user_id);
        return rolesService.deleteRole(roles);
    }
}
